package com.ruoyi.realEstate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.realEstate.domain.AtbRealEstateDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.realEstate.domain.AtbRealEstate;
import com.ruoyi.realEstate.service.IAtbRealEstateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地产Controller
 * 
 * @author ruoyi
 * @date 2024-09-16
 */
@RestController
@RequestMapping("/realEstate/realEstate")
public class AtbRealEstateController extends BaseController
{
    @Autowired
    private IAtbRealEstateService atbRealEstateService;

    /**
     * 查询地产列表
     */
    @PreAuthorize("@ss.hasPermi('realEstate:realEstate:list')")
    @GetMapping("/list")
    public TableDataInfo list(AtbRealEstate atbRealEstate)
    {
        startPage();
        List<AtbRealEstate> list = atbRealEstateService.selectAtbRealEstateList(atbRealEstate);
        return getDataTable(list);
    }

    /**
     * 导出地产列表
     */
    @PreAuthorize("@ss.hasPermi('realEstate:realEstate:export')")
    @Log(title = "地产", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AtbRealEstate atbRealEstate)
    {
        List<AtbRealEstate> list = atbRealEstateService.selectAtbRealEstateList(atbRealEstate);
        ExcelUtil<AtbRealEstate> util = new ExcelUtil<AtbRealEstate>(AtbRealEstate.class);
        util.exportExcel(response, list, "地产数据");
    }

    /**
     * 获取地产详细信息
     */
    @PreAuthorize("@ss.hasPermi('realEstate:realEstate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(atbRealEstateService.selectAtbRealEstateById(id));
    }

    /**
     * 新增地产
     */
    @PreAuthorize("@ss.hasPermi('realEstate:realEstate:add')")
    @Log(title = "地产", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AtbRealEstateDto atbRealEstateDto)
    {
        return toAjax(atbRealEstateService.insertAtbRealEstate(atbRealEstateDto));
    }

    /**
     * 修改地产
     */
    @PreAuthorize("@ss.hasPermi('realEstate:realEstate:edit')")
    @Log(title = "地产", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AtbRealEstate atbRealEstate)
    {
        return toAjax(atbRealEstateService.updateAtbRealEstate(atbRealEstate));
    }

    /**
     * 删除地产
     */
    @PreAuthorize("@ss.hasPermi('realEstate:realEstate:remove')")
    @Log(title = "地产", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(atbRealEstateService.deleteAtbRealEstateByIds(ids));
    }
}
